from time import sleep

from selenium import  webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait  # 显示等待
from selenium.webdriver.support import  expected_conditions#   #判断条件模块
from selenium.webdriver.support.select import Select    # 下拉框模块


driver = webdriver.Chrome()
# 隐式等待 : 在等待时间内整个页面完成加载,
# driver.implicitly_wait(5)
driver.get("http://192.168.1.138/ranzhi/www/sys/index.html")
driver.maximize_window()
#显示等待 : 判断每个要操作的元素是否出现,出现则操作,不出现则抛出异常
#1判断元素是否完成加载
# 传入浏览器对象 driver ,设置元素等待时间
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="account"]')))
driver.find_element(By.XPATH, '//*[@id="account"]').send_keys("admin")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="password"]')))
driver.find_element(By.XPATH, '//*[@id="password"]').send_keys("123456")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="submit"]')))
driver.find_element(By.XPATH, '//*[@id="submit"]').click()
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="s-menu-superadmin"]/button/i')))
driver.find_element(By.XPATH,'//*[@id="s-menu-superadmin"]/button/i').click()
#框架切入
WebDriverWait(driver,10).until(expected_conditions.frame_to_be_available_and_switch_to_it("iframe-superadmin"))
# driver.switch_to.frame("iframe-superadmin")#进入框架iframe-superadmin
#3 判断元素中的value属性是某个值
# expected_conditions.text_to_be_present_in_element_value()
#4 判断园中的attrubute是某个值
# expected_conditions.text_to_be_present_in_element_attribute()
# 5 判断超链接中是否含有预期的文本
# expected_conditions.text_to_be_present_in_element()
# 6 判断是否出现了弹出框
# 弹出框 元素无法定位
# 1.alert = driver.switch_to.alert() 切入到弹出框,并存入变量alert
# 2. 获取弹出框的文本信息 alert.text
# 3. 点击确定按钮 alert.accept()
# 4. 点击取消按钮 alert.dismiss()
# 5. 给弹出的文本框输入值 alert.send_keys()
# expected_conditions.alert_is_present()
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="shortcutBox"]/div/div[1]/div/a/h3')))
driver.find_element(By.XPATH,'//*[@id="shortcutBox"]/div/div[1]/div/a/h3').click()

#定位到下拉框
ele=WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,'role')))
# ele = driver.find_element(By.ID,"role")
#创建 下拉框对象
sle_obj=Select(ele)
#调用 方法
# sle_obj.select_by_index(2) #根据索引
# sle_obj.select_by_visible_text("研发")  #根据文本内容
sle_obj.select_by_value("office")   #根据value的值 在源代码中查看
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"account")))
driver.find_element(By.ID,"account").send_keys("zhaoyun")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"realname")))
driver.find_element(By.ID,"realname").send_keys("赵云")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"genderm")))
driver.find_element(By.ID,"genderm").click()
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"password1")))
driver.find_element(By.ID,"password1").send_keys("123456")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"password2")))
driver.find_element(By.ID,"password2").send_keys("123456")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"email")))
driver.find_element(By.ID,"email").send_keys("l28666666@gmail.com")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"submit")))
driver.find_element(By.ID,"submit").click()
driver.switch_to.parent_frame()#返回上一级框架

driver.find_element(By.LINK_TEXT,"签退").click()
